﻿using System.Collections.Generic;
using System.Linq;

namespace Project5188.BUS
{
    public class ScreenRoles : DetailView<screenrole>
    {
        private project5188Entities _context;
        // ReSharper disable InconsistentNaming
        private new List<screenrole> EntityList;
        private new screenrole Entity;
        // ReSharper restore InconsistentNaming

        public long TransactionId { get; private set; }

        #region Overrides of DetailView<screenrole>

        public override List<screenrole> GetEntityList()
        {
            _context = new project5188Entities();
            EntityList = _context.screenroles.Where(a => !a.IsDeleted).OrderBy(a => a.ID).ToList();

            return EntityList;
        }

        public override List<screenrole> GetEntityById(long id)
        {
            _context = new project5188Entities();
            EntityList = _context.screenroles.Where(a => a.ID == id && !a.IsDeleted).OrderBy(a => a.ID).ToList();

            return EntityList;
        }

        public override screenrole GetEntity()
        {
            _context = new project5188Entities();
            Entity = new screenrole();
            return Entity;
        }

        public override void Update()
        {
            _context.SaveChanges();
        }

        public override void Insert()
        {
            _context.AddToscreenroles(Entity);
            _context.SaveChanges();
            TransactionId = Entity.ID;
        }

        #endregion

        public bool HasRight(int screenId, int roleGroupId)
        {
            _context = new project5188Entities();

            return
                _context.screenroles.Where(a => a.ScreenID == screenId && a.RoleGroupID == roleGroupId).Count() > 0;
        }
    }
}
